package 力扣日常刷题.木23一月.第09天309;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/3/9
 * @description
 */
public class Demo34链表中倒数第k个节点 {


    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode p1 = head;
        ListNode p2 = head;

        for (int i = 0; i < k; i++) {
            p1 = p1.next;
        }


        while(p1!= null) {
            p1=p1.next;
            p2=p2.next;
        }
        return p2;
    }



}
